import $https from "../../https/https"
import $api from "../../https/Api"
// pages/goods_list/goods_list.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
      title:"",
      goodsList: [],
      total: 0,
      isloading: false,
      page:{
        pagenum:1,
        pagesize:20
      }
  },
  clickgoods(e){
    console.log(e.currentTarget.dataset.goods_id)
    wx.navigateTo({
      url: '/pages/goods_detail/main?goods_id='+e.currentTarget.dataset.goods_id,
    })
  },
    getgoodsList(){
      var than=this
      than.data.isloading=true
      $https.get($api.goods,"GET",{query:than.data.title,pagenum:than.data.page.pagenum}).then((res)=>{
        var goode = than.data.goodsList
        goode.push(...res.message.goods)
        console.log(res.message)
        than.setData({
          goodsList:goode,
          total:res.message.total,
          isloading:false
        })
        console.log(than.data.goodsList)
      })
    },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    var than= this
    console.log(options.query)
    than.setData({
      title:options.query
    })
    than.getgoodsList()
    
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {
    console.log("触底1")
    console.log("page="+this.data.page.pagenum*this.data.page.pagesize)
    if(this.data.page.pagenum*this.data.page.pagesize<this.data.total){
      this.data.page.pagenum=this.data.page.pagenum+1
      console.log(this.data.page.pagenum)
      this.getgoodsList()
    }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})